// src/router/index.js 就是当前项目的路由模块
import Vue from 'vue'
import VueRouter from 'vue-router'
//导入需要的组件

//把VueRouter 安装为Vue项目的插件
//Vue.use() 函数的作用，就是来安装插件的
Vue.use(VueRouter)
import Layout from '@/views/Layout.vue'
import MainShow from "@/views/MainShow.vue";
import StoreShow from "@/views/Store.vue";
import Login from "@/views/Login.vue";
import Dishone from '@/views/Dishone'
import backstage from '@/views/backstage/BackstageMain';
import allStore from '@/views/backstage/AllStore';
import unaudited from '@/views/backstage/Unaudited';
import audited from '@/views/backstage/Audited';
import users from '@/views/backstage/Users';
import my from '@/views/individualCenter/My';
import myOrder from '@/views/individualCenter/MyOrder.vue';
import user from '@/views/individualCenter/User.vue';
import SearchList from "@/views/SearchList.vue";
import myStore from "@/views/backStore/MyStore.vue";
import orders from "@/views/backStore/Orders.vue";
import myInformation from "@/views/backStore/MyInformation.vue";
import myDish from "@/views/backStore/MyDish.vue";
import empty from "@/views/empty.vue";
import empty2 from "@/views/empty2.vue";
import ShopSettled from "@/views/ShopSettled.vue";

//创建路由的实例对象
const router = new VueRouter({
    routes:[
        {path:'/',redirect:'/layout'},
        {
            path:'/layout',
            component:Layout,
            redirect:'/mainShow',
            children:[
                {path:'/mainShow',component:MainShow},
                {path:'/storeShow/:id',component:StoreShow},
                {path:'/dishone/:orderList',component:Dishone},
                {path: '/shopSettled',component: ShopSettled},
                {
                    path:'/my',
                    component:my,
                    redirect:'/user',
                    children:[
                        {path:'/user',component:user},
                        {path:'/myOrder',component:myOrder},
                    ]
                },
                {path: '/searchList/:objList',component: SearchList},
                {
                    path: '/myStore',
                    component: myStore,
                    redirect:'/myDish',
                    children:[
                        {path: '/myDish',component: myDish},
                        {path: '/orders',component: orders},
                        {path: '/myInformation',component: myInformation},
                    ]
                }
            ]
        },
        {path: '/empty',component: empty},
        {path: '/empty2',component: empty2},
        {
            path:'/backstage',
            component:backstage,
            redirect:'/allStore',
            children:[
                {path:'/allStore',component:allStore},
                {path:'/unaudited',component:unaudited},
                {path:'/audited',component:audited},
                {path:'/users',component:users},
            ]
        },
    ]
})

//to 代表将要访问的路径
//from 代表从哪个路径跳转过来的
//next 标识放行 next('/login')强制跳转的login页面
// router.beforeEach(function(to,from,next){
//     if(to.path!='/login'){
//         var token = sessionStorage.getItem('token')
//         if(token!=null){
//             next()
//         }else{
//             next('/login')
//         }
//     }else{
//         next()
//     }
// })
export default router